<?php
namespace Admin\Controller;
use Think\Controller;
class CatalogController extends Controller {
	public function __construct(){
		parent::__construct();
		if(!$_SESSION['admin_is_login']){
			$this->error('没有登录',U('admin/auth/logout'));
		}
	}	
    public function index(){
    	$catalog=M('prodect_catalog')->where('parent_id=0')->select();
    	$this->assign('level1',$catalog);
    	$this->display();
     }
     public function add(){
     	$catalog=M('prodect_catalog')->where('parent_id=0')->select();
    	$this->assign('level1',$catalog);
     	$this->display();
     }
     public function do_add(){
     	$name=I('post.name');
     	$parent_id=I("post.parent_id");
     	M("prodect_catalog")->add(array(
     			'name'=>$name,
     			'parent_id'=>$parent_id
     		));
     	$this->success('添加成功',U('admin/catalog/index'));
     }
     public function edit($id){
     	$catalog=M('prodect_catalog')->where('id='.$id)->find();
        $this->assign("level1",M('prodect_catalog')->where('parent_id=0')->select());
    	$this->assign('catalog',$catalog);
     	$this->display();
     }
     public function do_edit(){
     	$id=I('post.id');
     	$name=I('post.name');
     	$parent_id=I("post.parent_id");
     	M("prodect_catalog")->where('id='.$id)->save(array(
     			'name'=>$name,
     			'parent_id'=>$parent_id
     		));
     	$this->success('编辑成功',U('admin/catalog/index'));
 	}
}